/*
 * Copyright (C) Pinnet Tech
 * All Rights Reserved.
 */
package com.wj.facedetect.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.wj.facedetect.commom.FaceDetectApplication;
import com.wj.facedetect.net.ReqUrls;

/**
 *
 */

public class PreferencesUtils {


    /**
     * 普通字段存放地址
     */
    public static final String TAG = "PreferencesUtils";
    public static final String SESSION_ID = "session_id";
    public static final String KU_ID = "ku_id";
    public static final String KU_ID_NAME = "ku_id_name";
    public static final String TASK_ID = "task_id";
    public static final String BASE_URL = "base_url";
    public static final String GW_BASE_URL = "gw_base_url";
    public static final String GW_BASE_URL_APP = "gw_base_url_app";
    public static final String GW_BASE_URL_IM = "gw_base_url_im";
    public static final String ACCOUNT = "account";
    public static final String PWD = "pwd";
    public static final String SUITABILITY = "suitability";
    public static final String CREATE_KU_ID = "create_ku_id";
    public static final String CLUSTER_ID = "cluster_id";
    public static final String USER_ID = "user_id";
    public static final String CHAT_IS_CREATE = "chat_create";
    public static final String IS_LOGIN = "is_login";
    public static final String READ_WARNING_ID = "read_warning_id";
    public static final String READ_MESSAGE_ID = "read_message_id";
    public static String SETTINGS_PREVIEW_SELECTED = "preview_selected";
    public static String SETTINGS_CROPIMAGE_OUTPUTPATH = "cropimage_outputpath";
    private SharedPreferences local;
    private static PreferencesUtils instance;

    private PreferencesUtils() {
        local = FaceDetectApplication.getContext().getSharedPreferences(TAG, Context.MODE_PRIVATE);
    }

    public static PreferencesUtils getInstance() {
        if (instance == null) {
            instance = new PreferencesUtils();
        }
        return instance;
    }


    public String getSharePreStr(String field) {
        String s = local.getString(field, "");//如果该字段没对应值，则取出字符串0
        return s;
    }

    public String getSharePreStrBaseUrl(String field) {
        String s = local.getString(field, ReqUrls.BASE_URL_DOMAIN);//如果该字段没对应值，则取出字符串0
        return s;
    }

    public String getSharePreStrGwBaseUrl(String field) {
        String s = local.getString(field, ReqUrls.GW_BASE_URL_DOMAIN);//如果该字段没对应值，则取出字符串0
        return s;
    }

    public String getSharePreStrGwBaseUrlApp(String field) {
        String s = local.getString(field, ReqUrls.GW_BASE_URL_APP);//如果该字段没对应值，则取出字符串0
        return s;
    }

    public String getSharePreStrGwBaseUrlIm(String field) {
        String s = local.getString(field, ReqUrls.BASE_URL_PUSH_IM);//如果该字段没对应值，则取出字符串0
        return s;
    }

    public String getSharePreStrClusterId(String field) {
        String s = local.getString(field, ReqUrls.CLUSTER_ID);//如果该字段没对应值，则取出字符串0
        return s;
    }

    //取出whichSp中field字段对应的int类型的值
    public int getSharePreInt(String field) {
        int i = local.getInt(field, Integer.MIN_VALUE);//如果该字段没对应值，则取出0
        return i;
    }

    //取出whichSp中field字段对应的int类型的值
    public int getSharePreInt(String field, int x) {
        int i = local.getInt(field, x);//如果该字段没对应值，则取出0
        return i;
    }

    //取出whichSp中field字段对应的int类型的值
    public int getSharePreSuitability(String field) {
        int i = local.getInt(field, 80);//如果该字段没对应值，则取出0
        return i;
    }

    //取出whichSp中field字段对应的int类型的值
    public float getSharePreFloat(String field) {
        float i = local.getFloat(field, 0);//如果该字段没对应值，则取出0
        return i;
    }

    //取出whichSp中field字段对应的boolean类型的值
    public boolean getSharePreBoolean(String field) {
        boolean i = local.getBoolean(field, false);//如果该字段没对应值，则取出0
        return i;
    }

    public boolean getSharePreBoolean(String field, boolean dflVal) {
        boolean i = local.getBoolean(field, dflVal);//如果该字段没对应值，则取出0
        return i;
    }

    //保存string类型的value到whichSp中的field字段
    public void putSharePre(String field, String value) {
        SharedPreferences.Editor editor = local.edit();
        editor.putString(field, value).commit();
    }

    //保存int类型的value到whichSp中的field字段
    public void putSharePre(String field, int value) {
        SharedPreferences.Editor editor = local.edit();
        editor.putInt(field, value).commit();
    }

    //保存float类型的value到whichSp中的field字段
    public void putSharePre(String field, float value) {
        SharedPreferences.Editor editor = local.edit();
        editor.putFloat(field, value).commit();
    }

    //保存boolean类型的value到whichSp中的field字段
    public void putSharePre(String field, Boolean value) {
        SharedPreferences.Editor editor = local.edit();
        editor.putBoolean(field, value).commit();
    }

    //清空保存的数据
    public void clearSharePre(Context mContext) {
        try {
            SharedPreferences.Editor editor = local.edit();
            editor.clear().commit();
        } catch (Exception e) {

        }
    }


}
